package com.fix.dao.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.fix.dao.UserDao;
import com.fix.entity.User;
import com.fix.util.DbPool;


public class UserDaoImpl implements UserDao {
	
	DbPool pool = DbPool.getPool();

	@Override
	public User login(String name, String pass) throws SQLException {
		
		String sql="SELECT * from user where uname=? and upass=?  ";
		Connection conn=  pool.getConn();
		QueryRunner runner = new QueryRunner();
		User user = (User)runner.query(conn, sql, new BeanHandler(User.class), name,pass);
		pool.back(conn);
		
		return user;
	}

	@Override
	public List<User> getUsers() throws SQLException {
		String sql="select * from user";
		Connection conn=  pool.getConn();
		QueryRunner runner = new QueryRunner();
		List list = (List)runner.query(conn, sql, new BeanListHandler<User>(User.class));
		pool.back(conn);
		return list;
	}

}
